package offer;

/**
 * 剑指 Offer 05. 替换空格
 */
public class ReplaceSpace {
    public static void main(String[] args) {
        ReplaceSpace rs = new ReplaceSpace();
        String str = "We are happy.";
        System.out.println(rs.replaceSpace(str));
    }

    public String replaceSpace(String s) {
        // String str = s.replaceAll(" ", "%20");
        StringBuilder sb = new StringBuilder();
        char[] cs = s.toCharArray();
        for (char c : cs) {
            if (c == ' ') {
                sb.append("%20");
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
